import pandas as pd
from ast import literal_eval
from pyecharts.faker import Faker
from pyecharts.charts import Scatter
from pyecharts.charts import Line,Bar
import pyecharts.options as opts

def line1():
    years = pd.read_csv(r'C:\Users\ASUS\Desktop\11结果.csv')
    data_list=[]
    for m in years:
        data_list_1 = []
        for i in range(12):
            year = 10
            a = list(literal_eval(years[str(m)][i][1:-1]))
            for j in a:
                first=round(j[0]*2)
                second=round(j[1]*1.5)
                third=round(j[2]*0.8)
                year += first+second+third
            # if(year>30):
            #
            #     data_list_1.append(year*10)
            # else:
            #     data_list_1.append(year*5)
            data_list_1.append(year)

        data_list.append(data_list_1)



    X=["2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"]
    Y=[0,0,0,0,0,0,0,0,0,0,0,0]
    Y2=[0,0,0,0,0,0,0,0,0,0,0,0]
    for i in data_list:
        for j in range(12):
            Y[j]+=i[j]
            Y2[j]=Y[j]/23

    print(Y)
    print(Y2)
    bar = (
        Bar(init_opts=opts.InitOpts(width="1600px", height="800px"))
        .add_xaxis(xaxis_data=X,
                )
        .add_yaxis(
            series_name="热度",
            y_axis=Y,
            category_gap=50,
            label_opts=opts.LabelOpts(is_show=False ),

            itemstyle_opts=opts.ItemStyleOpts(color="#0094ff")
        )
        .extend_axis(
            yaxis=opts.AxisOpts(
                name="热度指数",
                type_="value",
                min_=0,
                max_=28,
                interval=5,
                axislabel_opts=opts.LabelOpts(formatter="{value} "),
            )
        )
        .set_global_opts(
            tooltip_opts=opts.TooltipOpts(
                is_show=True, trigger="axis", axis_pointer_type="cross"

            ),
            xaxis_opts=opts.AxisOpts(
                type_="category",
                axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"),
            ),
            yaxis_opts=opts.AxisOpts(
                name="热度指数",
                type_="value",
                min_=0,
                max_=800,
                interval=100,
                axislabel_opts=opts.LabelOpts(formatter="{value} ml"),
                axistick_opts=opts.AxisTickOpts(is_show=True),
                splitline_opts=opts.SplitLineOpts(is_show=True),
            ),
        )
    )

    line = (
        Line()
        .add_xaxis(xaxis_data=X)
        .add_yaxis(
            series_name="热度指数趋势",
            yaxis_index=1,
            y_axis=Y2,
            label_opts=opts.LabelOpts(is_show=False),
        )
    )

    bar.overlap(line).render("拟合曲线2.html")



def line2():
    X=["0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
           "19", "20", "21", "22", "23", "24"]
    Y=[543,412,362,250,235,222,223,256,308,423,563,623,685,792,876,820,750,650,700,803,823,885,850,752,652]

    c = (
        Line()
            .add_xaxis(X)
            .add_yaxis("参数", Y, is_smooth=True,itemstyle_opts=opts.ItemStyleOpts(color="#0094ff"))
            .set_series_opts(
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),

        )
            .set_global_opts(
            title_opts=opts.TitleOpts(title="Line-面积图（紧贴 Y 轴）"),
            xaxis_opts=opts.AxisOpts(
                axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                is_scale=False,
                boundary_gap=False,
            ),
        )
            .render("line_areastyle_boundary_gap.html")
    )


line1()
